import {create} from "zustand";
import { devtools, persist} from "zustand/middleware";


type TBearStoreState = {
    bears: number
    increasePopulation: () => void;
    removeAllBear: () => void;
    [propNames: string]: any ;
}
export const useStore = create<TBearStoreState>()
(
    persist(
        devtools(
            (set) => ({
                bears: 0,
                size: 'big',
                color: 'red',
                increasePopulation: () => {
                    set(state => ({ bears: state.bears + 1 }))
                },
                removeAllBear: () => set(({ bears: 0 }))
            }),
            {
                name:"bear store",
            }
        ),
        {
            name:'bear store',
            partialize:(state)=>{
                Object.fromEntries(
                    Object.entries(state).filter(key=>!['size'].includes(key))
                )
                Object.entries(state).filter(key=>{
                    console.log(!['color'].includes(key))
                })
            }
            // partialize:state => ({color:state.color})
        }
    )
)
